<template>
	<view>
		<login :favlist='favlist'></login>
		<view class="my-fav">
			<text class="favName">我的收藏</text>
			<view class="noFav" v-if="!favlist">
				~~暂无收藏~~
			</view>
			<view class="fav-list">
				<view class="fav-item" v-for="(item,index) in favlist" :key='index'>
					<film-item :film='item'></film-item>
					<button type="default" class="btn-del" @click="deleteById(item)">删除</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				favlist:{},
				fav:{}
			};
		},
		// methods:{
		// 	deleteById(item){
		// 		this.favlist=uni.getStorageSync('favlist')
		// 		console.log('11')
		// 		console.log(this.favlist)
		// 		// console.log(item.id)
		// 		delete this.favlist[item.id]
			
		// 		console.log(this.favlist)
		// 		// this.favlist=this.favlist.splice(item.id,1)
		// 	}
		// },
		// onLoad() {
		// 	this.favlist=uni.getStorageSync('favlist')
		// 	console.log('11')
		// 	console.log(this.favlist)
		// 	// uni.setStorageSync('favlist',this.favlist)
		// 	this.userinfo=this.userinfo
		// },
		// onShow() {
		// 	// const favlist0=uni.getStorageSync('favlist')
		// 	// this.favlist[cover.url]=favlist0.cover_url
		// 	// console.log('112233')
		// 	// console.log(favlist0)
		// 	// this.favlist=favlist0
		// 	// this.favlist={
		// 	// 	'cover.url':favlist0.cover_url,
		// 	// 	// 'rating.value':favlist0.rating.value,
		// 	// 	'title':favlist0.title
		// 	// }
		// 	// this.favlist=filmdatas
		// 	// console.log('12')
		// 	// console.log(this.favlist)
		// 	// console.log('打印结束')
		// }
		methods:{
			deleteById(item){
				delete this.favlist[item.id]
				console.log(this.favlist)
				this.fav=this.favlist
				console.log(this.fav)
				this.favlist=this.fav
				uni.setStorageSync('favlist',this.favlist)
			}
		},
		// onLoad() {
		// 	this.favlist=uni.getStorageSync('favlist')
		// 	console.log(this.favlist)
			
		// },
		onShow(){
			this.favlist=uni.getStorageSync('favlist')
			console.log(this.favlist)
		}
	}
</script>

<style lang="scss">
.my-fav{
		width: 100%;
		height: 170rpx;
		background-color: #FFFFFF;
		padding: 30rpx;
		box-sizing: border-box;
		.favName{
			font-weight: bold;
		}
		.noFav{
			color: #999999;
			font-size: 30rpx;
			text-align: center;
		}
		.fav-list{
			width: 100%;
			display: flex;
			margin-top: 30rpx;
			flex-wrap: wrap;
			background-color: #FFFFFF;
			.fav-item{
				width: 33.33%;
				height: 350rpx;
				padding: 0 12rpx;
				box-sizing: border-box;
				// border: 1px solid red;
				margin-bottom: 100rpx;
				.btn-del{
					width:100%;
					height: 50rpx;
					line-height: 50rpx;
					border: 1px solid red;
					font-size: 28rpx;
					color: red;
				}
			}
		}
	}
</style>
